package edu.scnu.fans.fingertip.order.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import edu.scnu.fans.fingertip.order.output.OrderOutput;
import lombok.Data;

import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDateTime;

/**
 * 订单表
 */
@Data
@TableName("orders")
public class Orders {

    /**
     * 未支付状态
     */
    public static final int NOT_PAY_STATUS = 0;

    @TableId(type = IdType.AUTO)
    private Long id;

    private Instant created;
    private Instant updated;
    private boolean deleted;

    /** 用户id */
    private Long userId;
    /** 收件人 */
    private String receiver;
    /** 收件人手机号 */
    private String mobile;
    /** 收件人地址 */
    private String address;
    /** 总价 */
    private BigDecimal totalAmount;
    /** 订单备注 */
    private String remark;
    /** 订单状态 0:未支付; 1:已支付; 2:已发货; 3:已完成; 4:退款 */
    private Integer orderStatus;
    /** 支付时间 */
    private LocalDateTime payTime;
    /** 发货时间 */
    private LocalDateTime deliverTime;
    /** 完成时间 */
    private LocalDateTime finishTime;

    Orders() {
    }

    public Orders(Long userId) {
        this.userId = userId;
    }

    public OrderOutput transferToOutput() {
        return new OrderOutput(id, created, updated, userId, receiver, mobile, address, totalAmount, remark, orderStatus,
                payTime, deliverTime, finishTime);
    }
}
